package com.lee9213.conference.track.management.entity;

import com.lee9213.conference.track.management.util.StringUtil;

import java.io.Serializable;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.List;

/**
 * @author lee9213@163.com
 * @version 1.0
 * @date 2018-07-11 15:11
 */
public class TrackEntity implements Serializable {

    private List<SessionEntity> sessionEntities = new ArrayList<>();

    public List<SessionEntity> getSessionEntities() {
        return sessionEntities;
    }

    public void addSessionEntity(SessionEntity sessionEntity) {
        this.sessionEntities.add(sessionEntity);
    }

    public String getLastTime() {
        if (sessionEntities == null || sessionEntities.isEmpty()) {
            throw new RuntimeException();
        }
        int sessionSize = sessionEntities.size();
        SessionEntity sessionEntity = sessionEntities.get(sessionSize - 1);
        List<TalkEntity> talkEntities = sessionEntity.getTalkEntity();
        if(talkEntities.isEmpty()) {
            throw new RuntimeException();
        }
        int talkSize = talkEntities.size();
        TalkEntity talkEntity = talkEntities.get(talkSize - 1);
        String startTime = talkEntity.getStartTime();
        if (StringUtil.isNullOrEmpty(startTime)) {
            throw new RuntimeException();
        }
        LocalTime time = LocalTime.parse(talkEntity.getStartTime()).plusMinutes(talkEntity.getMinutes());
        return time.toString();
    }
}
